package server

import (
	"fmt"
	"net/http"
)

type Context struct {
	// 原装对象
	Req    *http.Request
	Writer http.ResponseWriter
	// 封装对象
	Request *Request
	Response *Response
	// 请求信息
	Method string
	Path   string
	// 响应数据
	StatusCode int
}

// newContext 返回 Context 实例
func newContext(w http.ResponseWriter, req *http.Request) *Context {
	return &Context{
		Req:    req,
		Writer: w,
		Method: req.Method,
		Path:   req.URL.Path,
	}
}

// SetHeader 设置响应头
func (c *Context) SetHeader(key string, value string) {
	c.Writer.Header().Set(key, value)
}

// String 返回字符串
func (c *Context) String(code int, format string, values ...interface{}) {
	c.Writer.Header().Set("Content-Type", "text/plain")
	c.Writer.WriteHeader(code)

	c.Writer.Write([]byte(fmt.Sprintf(format, values...)))
}
